/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUIPrecipicio.java
 *
 * Created on 6/12/2010, 10:51:36 PM
 */

package Precipicio;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.Timer;



/**
 *
 * @author jefferpc
 */
public class GUIPrecipicio extends javax.swing.JFrame implements ActionListener{

    /** Creates new form GUIPrecipicio */
    int escalones;
    int estadoIA,estadoJugador;
    boolean cederTurnoIA,cederTurnoJugador;
    String ganador;
    boolean orden;
    Timer dado;
    Timer espera;
    int contador,turno,resultado;
    ArbolMinMaxPrecipicio arbolPrecipicio;
    public GUIPrecipicio(boolean  orden) {
        initComponents();
        this.orden=orden;
        setVisible(true);
        inic();
        
    }
    public void inic()
    {
        espera=new Timer(2000, this);
        jbAceptar.setEnabled(false);
        dado=new Timer(100,this);
        contador=0;
        resultado=-1;
        jbCederTurno.addActionListener(this);
        jbTirarDado.addActionListener(this);
        escalones=8;
        estadoIA=0;
        estadoJugador=0;
        cederTurnoIA=false;
        cederTurnoJugador=false;
        ganador="";
        arbolPrecipicio=new ArbolMinMaxPrecipicio();
        arbolPrecipicio.setCantEscalones(escalones);
        turno=1;
        if(orden)
        {
            turno=0;
            jugar();
        }

    }

    public int getResultado() {
        return resultado;
    }

    

    public void jugar()
    {
        arbolPrecipicio.inicializar(estadoIA, estadoJugador, cederTurnoIA, cederTurnoJugador);
        String decision=arbolPrecipicio.tomarDecision();
        if(decision.equals("DADO"))
        {
            jbTirarDado.setEnabled(false);
            jbCederTurno.setEnabled(false);

            jlDado.setIcon(new ImageIcon("dado.gif"));
            dado.start();
        }
        else
        {
            cederTurnoIA=true;
            jbTirarDado.setEnabled(true);
            jbCederTurno.setEnabled(true);
            jtIA.append(">> Ceder Turno"+"\n");
            verificarGanador();
        }
        
        
    }
    public void verificarGanador()
    {
        if(estadoIA>8)
        {
            if(estadoJugador<=8)
            {
                jlResultado.setText("Ganaste!!");
                    resultado=1;

            }
            if(estadoJugador>8)
            {
                jlResultado.setText("Empate");
                    resultado=0;

            }
            jbAceptar.setEnabled(true);
            return;
        }
        if(estadoJugador>8)
        {
            if(estadoIA<=8)
            {
                jlResultado.setText("Perdiste!!");
                    resultado=2;
            }
            if(estadoIA>8)
            {
                jlResultado.setText("Empate");
                    resultado=0;
            }
            jbAceptar.setEnabled(true);
            return;
        }
        if(estadoIA==8&&estadoJugador==8)
        {
            jlResultado.setText("Empate");
            resultado=0;
            jbAceptar.setEnabled(true);
            return;
        }
        if(cederTurnoIA)
        {
            if(cederTurnoJugador)
            {
                if(estadoIA>estadoJugador)
                {
                    jlResultado.setText("Perdiste!!");
                    resultado=2;
                }
                if(estadoIA<estadoJugador)
                {
                    jlResultado.setText("Ganaste!!");
                    resultado=1;
                }
                else
                {
                    jlResultado.setText("Empate");
                    resultado=0;
                }
                jbAceptar.setEnabled(true);
                return;
            }
            if(estadoIA>=estadoJugador)
            {
                    
                jbTirarDado.setEnabled(true);
                 jbCederTurno.setEnabled(true);
            }
            if(estadoIA<estadoJugador)
            {
                    jlResultado.setText("Ganaste!!");
                    resultado=2;
                    jbAceptar.setEnabled(true);
                    return;
            }

        }
        if(cederTurnoJugador)
        {
            if(cederTurnoIA)
            {
                if(estadoIA>estadoJugador)
                {
                    jlResultado.setText("Perdiste!!");
                    resultado=2;
                }
                if(estadoIA<estadoJugador)
                {
                    jlResultado.setText("Ganaste!!");
                    resultado=1;
                }
                else
                {
                    jlResultado.setText("Empate");
                    resultado=0;
                }
                jbAceptar.setEnabled(true);
                return;
            }
            if(estadoIA>estadoJugador)
            {
                    jlResultado.setText("Perdiste!!");
                    resultado=2;
                    jbAceptar.setEnabled(true);
                    return;

            }
            if(estadoIA<=estadoJugador)
            {
                    jugar();
                    return;
            }

        }
        
        if(!cederTurnoIA&&!cederTurnoJugador)
        {
            if(turno%2==0)
            {
            jbTirarDado.setEnabled(true);
            jbCederTurno.setEnabled(true);
            }
            else
            {
                jugar();
            }
        }
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jlDado = new javax.swing.JLabel();
        jlYo = new javax.swing.JLabel();
        jlPosJugador = new javax.swing.JLabel();
        jlJugador = new javax.swing.JLabel();
        jlIA = new javax.swing.JLabel();
        jlPosIA = new javax.swing.JLabel();
        jbTirarDado = new javax.swing.JButton();
        jLabel38 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtIA = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtJugador = new javax.swing.JTextArea();
        jLabel39 = new javax.swing.JLabel();
        jlResultado = new javax.swing.JLabel();
        jbAceptar = new javax.swing.JButton();
        jbCederTurno = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel1.setBorder(null);
        jLabel1.setBounds(40, 70, 50, 30);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel2.setBorder(null);
        jLabel2.setBounds(40, 40, 50, 30);
        jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel3.setBorder(null);
        jLabel3.setBounds(40, 130, 50, 30);
        jLayeredPane1.add(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel4.setBorder(null);
        jLabel4.setBounds(40, 100, 50, 30);
        jLayeredPane1.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel5.setBorder(null);
        jLabel5.setBounds(40, 250, 50, 30);
        jLayeredPane1.add(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel6.setBorder(null);
        jLabel6.setBounds(40, 220, 50, 30);
        jLayeredPane1.add(jLabel6, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel7.setBorder(null);
        jLabel7.setBounds(40, 160, 50, 30);
        jLayeredPane1.add(jLabel7, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel8.setBorder(null);
        jLabel8.setBounds(40, 190, 50, 30);
        jLayeredPane1.add(jLabel8, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel9.setBorder(null);
        jLabel9.setBounds(90, 160, 50, 30);
        jLayeredPane1.add(jLabel9, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel10.setBorder(null);
        jLabel10.setBounds(90, 250, 50, 30);
        jLayeredPane1.add(jLabel10, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel11.setBorder(null);
        jLabel11.setBounds(90, 190, 50, 30);
        jLayeredPane1.add(jLabel11, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel12.setBorder(null);
        jLabel12.setBounds(90, 220, 50, 30);
        jLayeredPane1.add(jLabel12, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel13.setBorder(null);
        jLabel13.setBounds(90, 130, 50, 30);
        jLayeredPane1.add(jLabel13, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel14.setBorder(null);
        jLabel14.setBounds(90, 100, 50, 30);
        jLayeredPane1.add(jLabel14, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel15.setBorder(null);
        jLabel15.setBounds(90, 70, 50, 30);
        jLayeredPane1.add(jLabel15, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel16.setBorder(null);
        jLabel16.setBounds(140, 100, 50, 30);
        jLayeredPane1.add(jLabel16, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel17.setBorder(null);
        jLabel17.setBounds(140, 160, 50, 30);
        jLayeredPane1.add(jLabel17, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel18.setBorder(null);
        jLabel18.setBounds(140, 130, 50, 30);
        jLayeredPane1.add(jLabel18, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel19.setBorder(null);
        jLabel19.setBounds(140, 190, 50, 30);
        jLayeredPane1.add(jLabel19, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel20.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel20.setBorder(null);
        jLabel20.setBounds(140, 220, 50, 30);
        jLayeredPane1.add(jLabel20, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel21.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel21.setBorder(null);
        jLabel21.setBounds(140, 250, 50, 30);
        jLayeredPane1.add(jLabel21, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel22.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel22.setBorder(null);
        jLabel22.setBounds(190, 130, 50, 30);
        jLayeredPane1.add(jLabel22, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel23.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel23.setBorder(null);
        jLabel23.setBounds(190, 160, 50, 30);
        jLayeredPane1.add(jLabel23, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel24.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel24.setBorder(null);
        jLabel24.setBounds(190, 190, 50, 30);
        jLayeredPane1.add(jLabel24, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel25.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel25.setBorder(null);
        jLabel25.setBounds(190, 220, 50, 30);
        jLayeredPane1.add(jLabel25, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel26.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel26.setBorder(null);
        jLabel26.setBounds(190, 250, 50, 30);
        jLayeredPane1.add(jLabel26, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel27.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel27.setBorder(null);
        jLabel27.setBounds(240, 220, 50, 30);
        jLayeredPane1.add(jLabel27, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel28.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel28.setBorder(null);
        jLabel28.setBounds(240, 250, 50, 30);
        jLayeredPane1.add(jLabel28, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel29.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel29.setBorder(null);
        jLabel29.setBounds(240, 190, 50, 30);
        jLayeredPane1.add(jLabel29, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel30.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel30.setBorder(null);
        jLabel30.setBounds(240, 160, 50, 30);
        jLayeredPane1.add(jLabel30, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel31.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel31.setBorder(null);
        jLabel31.setBounds(290, 190, 50, 30);
        jLayeredPane1.add(jLabel31, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel32.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel32.setBorder(null);
        jLabel32.setBounds(290, 220, 50, 30);
        jLayeredPane1.add(jLabel32, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel33.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel33.setBorder(null);
        jLabel33.setBounds(290, 250, 50, 30);
        jLayeredPane1.add(jLabel33, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel34.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel34.setBorder(null);
        jLabel34.setBounds(390, 250, 50, 30);
        jLayeredPane1.add(jLabel34, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel35.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel35.setBorder(null);
        jLabel35.setBounds(340, 220, 50, 30);
        jLayeredPane1.add(jLabel35, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel36.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/arena.jpg"))); // NOI18N
        jLabel36.setBorder(null);
        jLabel36.setBounds(340, 250, 50, 30);
        jLayeredPane1.add(jLabel36, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jlDado.setFont(new java.awt.Font("DejaVu Sans", 0, 36));
        jlDado.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlDado.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Precipicio/3.jpg"))); // NOI18N
        jlDado.setBorder(null);
        jlDado.setBounds(130, 300, 60, 60);
        jLayeredPane1.add(jlDado, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jlYo.setText("YO");
        jlYo.setBounds(460, 210, 20, 17);
        jLayeredPane1.add(jlYo, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jlPosJugador.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlPosJugador.setText("0");
        jlPosJugador.setBounds(460, 230, 10, 17);
        jLayeredPane1.add(jlPosJugador, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jlJugador.setBackground(new java.awt.Color(215, 7, 15));
        jlJugador.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jlJugador.setOpaque(true);
        jlJugador.setBounds(460, 250, 10, 30);
        jLayeredPane1.add(jlJugador, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jlIA.setBackground(new java.awt.Color(1, 75, 46));
        jlIA.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jlIA.setOpaque(true);
        jlIA.setBounds(480, 250, 10, 30);
        jLayeredPane1.add(jlIA, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jlPosIA.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlPosIA.setText("0");
        jlPosIA.setBounds(480, 230, 10, 17);
        jLayeredPane1.add(jlPosIA, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jbTirarDado.setText("Tirar Dado");
        jbTirarDado.setBounds(240, 290, 140, 29);
        jLayeredPane1.add(jbTirarDado, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel38.setText("Escalador (IA)");
        jLabel38.setBounds(540, 20, 90, 17);
        jLayeredPane1.add(jLabel38, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jtIA.setColumns(8);
        jtIA.setEditable(false);
        jtIA.setRows(5);
        jScrollPane1.setViewportView(jtIA);

        jScrollPane1.setBounds(540, 40, 130, 120);
        jLayeredPane1.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jtJugador.setColumns(8);
        jtJugador.setEditable(false);
        jtJugador.setRows(5);
        jScrollPane2.setViewportView(jtJugador);

        jScrollPane2.setBounds(540, 180, 130, 120);
        jLayeredPane1.add(jScrollPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel39.setText("Jugador");
        jLabel39.setBounds(540, 160, 90, 17);
        jLayeredPane1.add(jLabel39, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jlResultado.setFont(new java.awt.Font("DejaVu Sans", 0, 24));
        jlResultado.setBounds(500, 310, 140, 30);
        jLayeredPane1.add(jlResultado, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jbAceptar.setText("Aceptar");
        jbAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cerrar(evt);
            }
        });
        jbAceptar.setBounds(510, 340, 110, 29);
        jLayeredPane1.add(jbAceptar, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jbCederTurno.setText("Ceder turno");
        jbCederTurno.setBounds(240, 330, 140, 30);
        jLayeredPane1.add(jbCederTurno, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 674, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cerrar(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cerrar
        // TODO add your handling code here:

        dispose();
    }//GEN-LAST:event_cerrar

    /**
    * @param args the command line arguments
    */
   /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUIPrecipicio(true).setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbAceptar;
    private javax.swing.JButton jbCederTurno;
    private javax.swing.JButton jbTirarDado;
    private javax.swing.JLabel jlDado;
    private javax.swing.JLabel jlIA;
    private javax.swing.JLabel jlJugador;
    private javax.swing.JLabel jlPosIA;
    private javax.swing.JLabel jlPosJugador;
    private javax.swing.JLabel jlResultado;
    private javax.swing.JLabel jlYo;
    private javax.swing.JTextArea jtIA;
    private javax.swing.JTextArea jtJugador;
    // End of variables declaration//GEN-END:variables

    public void actionPerformed(ActionEvent ae) {
        Object evento=ae.getSource();
        if(evento==dado)
        {
            
            
            contador++;
            if(contador==24)
            {
                int numero=(int)((Math.random()*3)+1);
                jlDado.setIcon(new ImageIcon(numero+".jpg"));
                if(!((turno%2)==0))
                {
                    estadoJugador+=numero;
                    jlPosJugador.setText(""+estadoJugador);
                    jlYo.setBounds(460-(estadoJugador*50), 210-(estadoJugador*30), 20, 18);
                    jlPosJugador.setBounds(460-(estadoJugador*50), 230-(estadoJugador*30), 10, 18);
                    jlJugador.setBounds(460-(estadoJugador*50), 250-(estadoJugador*30), 10, 30);
                    jtJugador.append(">> Dado "+numero+"\n");
                }
                else
                {
                    estadoIA+=numero;
                    jlPosIA.setText(estadoIA+"");
                    jlPosIA.setBounds(480-(estadoIA*50), 230-(estadoIA*30), 10, 18);
                    jlIA.setBounds(480-(estadoIA*50), 250-(estadoIA*30), 10, 30);
                    jtIA.append(">> Dado "+numero+"\n");
                }

                contador=0;
                dado.stop();
                espera.start();
                
                
            }

        }
        if(evento==espera)
        {
            espera.stop();
            verificarGanador();
                turno++;
                if(cederTurnoIA||cederTurnoJugador)
                turno++;
        }
        if(evento==jbTirarDado)
        {

            jbTirarDado.setEnabled(false);
            jbCederTurno.setEnabled(false);
            
            jlDado.setIcon(new ImageIcon("dado.gif"));
            dado.start();
        }
        if(evento==jbCederTurno)
        {
            jtJugador.append(">> Cerder Turno"+"\n");
            cederTurnoJugador=true;
            jbTirarDado.setEnabled(false);
            jbCederTurno.setEnabled(false);
            verificarGanador();
            turno++;
        }
    }

}
